package com.emep.changzhi.analyse.service.datamonitor.realtime;

import com.emep.changzhi.analyse.entity.datamonitor.realtime.VehicleEmissionsRealtime;
import com.emep.changzhi.analyse.repository.datamonitor.realtime.VehicleEmissionsRealtimeRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;
import java.util.Map;

/**
 * @author xy
 * @Description: 机动车尾气监测_实时数据业务层
 * @date 2018/2/27 11:59
 * @version V1.0
 */
@Slf4j
@Service
public class VehicleEmissionsRealtimeService {
    
    @Resource
    private VehicleEmissionsRealtimeRepository vehicleEmissionsRealtimeRepository;


    /**
     *
     * 新增机动车尾气监测_实时数据
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public VehicleEmissionsRealtime save(Map<String, Object> payload) {
        VehicleEmissionsRealtime VehicleEmissionsRealtime = null;
        try {
            VehicleEmissionsRealtime VehicleEmissionsRealtime1 = (VehicleEmissionsRealtime) MapUtils.convertMap(VehicleEmissionsRealtime.class,payload);
            VehicleEmissionsRealtime = vehicleEmissionsRealtimeRepository.save(VehicleEmissionsRealtime1);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return VehicleEmissionsRealtime;
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 10:11
     * @version V1.0
     */
    public List<VehicleEmissionsRealtime> findVehicleEmissionsRealtimeByHome(Integer pageSize){
        List<VehicleEmissionsRealtime> vehicleEmissionsRealtimes = null;
        try {
            vehicleEmissionsRealtimes = vehicleEmissionsRealtimeRepository.vehicleEmissionsRealtimeHome(pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return vehicleEmissionsRealtimes;

    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 10:18
     * @version V1.0
     */

    public List<VehicleEmissionsRealtime> findVehicleEmissionsRealtimeByFlip(String id,Integer pageSize) {
        List<VehicleEmissionsRealtime> vehicleEmissionsRealtimes = null;
        try {
            vehicleEmissionsRealtimes = vehicleEmissionsRealtimeRepository.vehicleEmissionsRealtimeFlip(id,pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return vehicleEmissionsRealtimes;
    }

}
